/***************************************************************************
 *   This is a part of the NextCAD Web APP.                                *
 *   Copyright (C) AMCAX, All rights reserved.                             *
 ***************************************************************************/
/*
 * @Descripttion:
 * @version: 1.0.0
 * @Author: YinJianFeng
 * @Date: 2024-03-29 16:26:48
 */
import { Interactor2 } from '@app-cad/common/base/Interactor2';
import { RendererMgr, Renderer3D } from '@amcax/renderer';

import { previewer } from '@app-cad/module';
import { Vector3 } from 'three-legacy';
import { modelMover } from './ModelMover';

interface IParams {
  gallery: string;
  placement?: number[][];
}
export default class CmdInteractor extends Interactor2<IParams> {
  /**
   * 初始化参数
   * @returns
   */
  initParams(): IParams {
    return {
      gallery: '',
      placement: [],
    };
  }

  /**
   * 返回事务执行参数
   * 如果返回有参数，正常执行Transaction
   * 如果返回null，不执行Transaction
   * @returns
   */
  getExecuteParams(params: IParams) {
    return {
      gallery: params.gallery,
      placement: params.placement,
    };
  }

  async preview(result: any) {
    const models =
      await RendererMgr.getRender<Renderer3D>('3d').parsePreviewModels(result);
    if (models?.length > 0) {
      previewer.preview(models);
      modelMover.exit();
      modelMover.startMove(models[0], new Vector3(0, 0, 0));
    }
  }
}
